require(['highcharts', 'highcharts-more'], function () {
    window.loadData = function (data) {
        // -- 界面一加载就加载数据

        if (data.length > 0) {
            var remark = "【" + data[0].rcrdDate + '>' + data[0].licPltNo + "】设备在离线变化";
            $.ajaxExt({
                url: "/deviceOnline/getDeviceOnlineDetail.htm",
                data: {
                    carId: data[0].carId,
                    rcrdDate: data[0].rcrdDate
                }
            }).done(function (result) {
                var daysArr = [];
                var daysChart = [];
                $(result).each(function (i, item) {
//                	console.info(item);
                	if(item.onlineSt!=null){
                		daysArr.push([item.rcrdTimeChange, parseInt(item.onlineSt)]);
                	}
                	if(item.task!=null){
                		daysChart.push([item.dispatchstarttime, parseInt(item.task)]);
                        daysChart.push([item.endtriptime, parseInt(item.task)]);
                	}
                    
                });
                $("#equipHighcharts").highcharts({
                    chart: {
                        zoomType: 'x',
                        plotBorderWidth: 1,
                        marginTop: 38,
                        marginLeft: 90,
    					marginRight: 330,
                        height: $(document).height() - 30,
                        width: $(document).width()
                    },
                    title: {
                        text: ''
                    },
                    credits: {
                        enabled: false
                    },
                    legend: {
                        //enabled:false
                    },
                    tooltip: {
                        shared: true,
                        formatter: function () {
                            var html = '时间:' + new Date(this.x - 1000 * 60 * 60 * 8).format('yyyy-MM-dd hh:mm:ss') + '<br>';
                            return html;
                        },
                        crosshairs: true
                    },
                    xAxis: {
                        tickmarkPlacement: 'on',
                        type: 'datetime'
                    },
                    yAxis: [
                        {
                            min: 0,
                            title: {
                                text: ''
                            },
                            labels: {
                                formatter: function () {
//                                	console.info(this.value);
                                    if (this.value == 1) {
                                        return '在线';
                                    } else if (this.value == 0) {
                                        return '离线';
                                    }
//                                    else if (this.value == 2) {
//                                        return '出场';
//                                    } else if (this.value == 3) {
//                                        return '入场';
//                                    } else if (this.value == 4) {
//                                    	return '短线';
//                                    } else if (this.value == 5) {
//                                    	return '区间';
//                                    } else if (this.value == 6) {
//                                    	return '全程';
//                                    } else if (this.value == 7) {
//                                    	return '复行';
//                                    } else if (this.value == 8) {
//                                    	return '单班中停';
//                                    }
                                    return '';
                                }
                            },
                            minorGridLineWidth: 0,
                            gridLineWidth: 1,
                            alternateGridColor: null,
                            plotBands: [{ // Light air
                                from: 0.9,
                                to: 1.1,
                                color: 'rgba(68, 170, 213, 0.1)'
                            },
                                { // Light air
                                    from: 0,
                                    to: 0.2,
                                    color: 'rgba(68, 170, 213, 0.1)'
                                }

                            ]
                        }
                        ,
                        { // Secondary yAxis
    			            title: {
    			                text: '任务',
    			                style: {
    			                    color: '#FA5555'
    			                }
    			            },
    			            labels: {
    			            	formatter: function () {
//                                	console.info(this.value);
                                    if (this.value == 2) {
                                        return '出场';
                                    } else if (this.value == 3) {
                                        return '入场';
                                    } else if (this.value == 4) {
                                    	return '短线';
                                    } else if (this.value == 5) {
                                    	return '区间';
                                    } else if (this.value == 6) {
                                    	return '全程';
                                    } else if (this.value == 7) {
                                    	return '复行';
                                    } else if (this.value == 8) {
                                    	return '单班中停';
                                    }
                                    return '';
                                }
    			            },
    			            opposite: true
    			        }
                    ],
                    series: [
                        {
                            data: daysArr,
                            name: remark,
                            marker: {
                                enabled: false
                            }
                        },
                        {
    						data: daysChart,
    						name: '车辆任务变化',
    						yAxis: 1,
    						color: '#FA5555',
    						marker: {
    							enabled: false
    						}
    					}
                    ]
                });
            });
        }
    }
});